
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;


public class MainPanel extends JPanel{
	private DataManager data;
	private JButton submit;
	private JLabel labelText;
	private GridBagConstraints c;
	private JLabel labelText2;
	private JLabel labelText3;
	private JTextPane tText1;
	private JTextPane tText2;
	protected int k;
	
	public MainPanel(DataManager newData){
		
		setLayout(new GridBagLayout());
		c = new GridBagConstraints();
		
		labelText = new JLabel("Settlement Values");
		Font font = new Font("Verdana", Font.BOLD, 24);
		labelText.setFont(font);
		
		labelText2 = new JLabel("Diameter");
		
		tText1 = new JTextPane();
		tText1.setText("50");
		
		labelText3 = new JLabel("Stations");
		
		tText2 = new JTextPane();
		tText2.setText("8");
		
		final String[] columnNames = {"Location",
								"Elevation",
								"Arc Length"};
		Object[][] tableData0 = {{new Integer(0),new Integer(0),new Integer(0)}};
		JTable myTable = new JTable(tableData0,columnNames);
		
		data = newData;
		submit = new JButton("Submit This");
		submit.addActionListener(new ActionListener() {
            private JTextPane newText;
			private JTextPane newText2;

			public void actionPerformed(ActionEvent e)
            {
				
            	//double myDegs = 0;
				//
            	//load up variables in the dataManager from the form
                //Execute when button is pressed
                for(k = 1;k < data.submit(tText2.getText());k++){
                	/*
                	//Location Label
            		c.fill = GridBagConstraints.BOTH;
            		c.gridy = k;
            		c.gridx = 0;
            		c.gridwidth = 1; 
            		c.insets = new Insets(0,0,0,0);  //padding
                	add(formCol1(k-4),c);
                	
                	//Elevations
                	c.gridy = k;
                	c.gridx = 1;
            		c.insets = new Insets(0,5,0,0);  //padding
                	add(formCol2(),c);
                	
                	//Location Degrees
                	c.gridy = k;
                	c.gridx = 2;
                	add(formCol3(myDegs),c);
                	myDegs = myDegs + (data.submit(tText1.getText())*Math.PI)/data.submit(tText2.getText());
                	myDegs = myDegs*100;
                	myDegs = Math.round(myDegs);
                	myDegs = myDegs/100;
                	*/
                }
            }
/*
			private Component formCol1(int myDegs) {
				newText = new JTextPane();
				newText.setText(Integer.toString(myDegs));
				return newText;
			}
			
			private Component formCol2() {
				newText2 = new JTextPane();
				newText2.setText("1");
				return newText2;
			}

			private Component formCol3(double myDegs) {
				newText = new JTextPane();
				newText.setText(Double.toString(myDegs));
				return newText;
			}
			*/
        });
		
		//setBackground(Color.GREEN);
		
		//Set the title "Settlement Values"
		c.gridx = 0;       //aligned at left
		c.gridy = 0;       //first row
		c.gridwidth = 3;   //3 columns wide
		add(labelText,c);

		//Set the label "Diameter"
		c.gridx = 0;
		c.gridy = 1;
		c.gridwidth = 1;
		c.insets = new Insets(0,0,0,0);
		add(labelText2,c);

		//Set the textbox with the default of 50 (diameter)
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 1;
		c.gridy = 1;       //second row
		c.gridwidth = 1;   //1 column wide
		c.weighty = 1.0;
		c.weightx = 1.0;   //request any extra horizontal space
		add(tText1,c);
		
		//Set the label "Stations"
		c.gridx = 0;
		c.gridy = 2;
		c.gridwidth = 1;
		c.insets = new Insets(0,10,0,0);  //padding
		add(labelText3,c);
		
		//Set the textbox with the default of 8 (stations)
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 1;
		c.gridy = 2;       //second row
		c.gridwidth = 1;   //1 column wide
		c.insets = new Insets(0,0,0,0);  //padding
		c.weighty = 1.0;
		c.weightx = 1.0;   //request any extra horizontal space
		add(tText2,c);

		//Show the button to update the grid
		c.fill = GridBagConstraints.NONE;
		c.gridx = 2;       
		c.gridy = 1;       //third row
		c.gridwidth = 1;   //1 column wide
		c.gridheight = 2;
		c.ipady = 0;
		c.weighty = 1.0;
		c.insets = new Insets(0,0,0,0);  //padding
		add(submit,c);
		
		c.gridx = 0;
		c.gridy = 3;
		c.gridwidth = 3;
		c.insets = new Insets(10,0,0,0);
		add(myTable,c);
		
	}

}
